{% extends "bootstrap/base.html" %}
{% block title %}213宿舍管理系统{% endblock %}
{% block navbar %}
<div class="navbar navbar-inverse" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle"data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/#">超腾信息</a>
        </div>
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li><a href="#"></a></li>
                {% block base_content %}

                {% endblock %}
            </ul>
        </div>
    </div>
</div>
{% endblock %}
{% block content %}
<div class="container">
    <div style="margin:100px">
        <div style="width:50%; float:left">
            <a href="#"><img src="/static/images/email.png" alt="超腾信息" height="300px" width="300px"></a>
        </div>
        <div style="width:50%; float:right;">
        <form style="margin:100px">
            <div class="input-group">
                <span class="input-group-addon">邮箱</span>
                <input type="text" class="form-control" placeholder="Email" id="email">
            </div><br>
            <div class="input-group">
                <span class="input-group-addon">密码</span>
                <input type="password" class="form-control" placeholder="Password" id="password">
            </div><br>
            <div style="text-align:center;margin:10px">
                <button type="button" class="btn btn-default" onclick="login()">登录</button><br>
                <a href="/register">去注册</a>
            </div>
        </form>
        </div>
    </div>
</div>
{% block styles %}
<link rel="stylesheet" href="/static/css/toastr.min.css">
{{super()}}
{% endblock %}
{% block scripts %}
<script src="/static/js/jquery-3.2.1.min.js"></script>
<script src="/static/js/toastr.min.js"></script>
<script src=""></script>
{{super()}}
{% endblock %}
<script>

    // 登录
    //账号密码检测
    function login(){
        var re=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
        if(re.test($("#email").val()) != true){
            toastr['error']("邮箱格式错误") // 邮箱格式检测
        }else{
            if($('#password').val()){     // 密码是否填写检测
                formdata = {
                    'email':$('#email').val(),
                    'password':$('#password').val()
                }
                $.ajax({
                    data:JSON.stringify(formdata),
                    url:'/login',
                    type:'POST',
                    dataType:'json',
                    contentType:'application/json',
                    success: function(result){
                        if(result.Result == 'ERR'){
                            toastr['error'](result.Reason)
                        }else{
                            
                        }
                    },
                    error:function(){
                        toastr['error']("连接失败")
                    }
                })
            }else{
                toastr['error']("不存在密码")
            }
        }
    }
</script>
{% endblock %}